//
//  LabelCell.m
//  UI_HLJ_Frame
//
//  Created by  毕宏伟 on 15/6/30.
//  Copyright (c) 2015年 毕宏伟. All rights reserved.
//

#import "LabelCell.h"
#import "AFNetworking.h"
#import "UIImageView+WebCache.h"
#import "labelModel.h"
#import "UIButton+WebCache.h"

#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height


@implementation LabelCell
- (void)dealloc
{
    [_oneLabel release];
    [_twoLabel release];
    [_threeLabel release];
    [_fourButton release];
    [_fiveLabel release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.oneButton =[UIButton buttonWithType:UIButtonTypeCustom];
        self.oneButton.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.oneButton];
        
        self.twoButton =[UIButton buttonWithType:UIButtonTypeCustom];
        self.twoButton.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.twoButton];
        
        self.threeButton =[UIButton buttonWithType:UIButtonTypeCustom];
        self.threeButton.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.threeButton];
        
        self.fourButton =[UIButton buttonWithType:UIButtonTypeCustom];
        self.fourButton.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.fourButton];
        
        self.fiveButton =[UIButton buttonWithType:UIButtonTypeCustom];
        self.fiveButton.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.fiveButton];
        
        self.sixButton =[UIButton buttonWithType:UIButtonTypeCustom];
        self.sixButton.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.sixButton];
        
        
        
        //设置label
        self.oneLabel = [[UILabel alloc]init];
        self.oneLabel.backgroundColor =[UIColor whiteColor];
        self.oneLabel.textAlignment =1;
        [self.contentView addSubview:self.oneLabel];
        
        self.twoLabel = [[UILabel alloc]init];
        self.twoLabel.backgroundColor = [UIColor whiteColor];
        self.twoLabel.textAlignment =1;
        [self.contentView addSubview:self.twoLabel];
        [_twoLabel release];
        
        self.threeLabel = [[UILabel alloc]init];
        self.threeLabel.backgroundColor = [UIColor whiteColor];
        self.threeLabel.textAlignment =1;
        [self.contentView addSubview:self.threeLabel];
        [_threeLabel release];
        
        self.fourLabel = [[UILabel alloc]init];
        self.fourLabel.backgroundColor = [UIColor whiteColor];
        self.fourLabel.textAlignment =1;
        [self.contentView addSubview:self.fourLabel];
        [_fourLabel release];
        
        self.fiveLabel = [[UILabel alloc]init];
        self.fiveLabel.backgroundColor = [UIColor whiteColor];
        self.fiveLabel.textAlignment =1;
        [self.contentView addSubview:self.fiveLabel];
        [_fiveLabel release];
        
        self.sixLabel = [[UILabel alloc]init];
        self.sixLabel.backgroundColor = [UIColor whiteColor];
        self.sixLabel.textAlignment =1;
        [self.contentView addSubview:self.sixLabel];
        [_sixLabel release];
        [self createData];
        
        
    }
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.oneButton.frame = CGRectMake(WIDTH / 18.75, 20 , WIDTH / 3.75, 100);
    
    
    self.twoButton.frame =CGRectMake(WIDTH / 2.67, 20, WIDTH / 3.75, 100);
    
    self.threeButton.frame = CGRectMake(WIDTH / 1.45, 20, WIDTH / 3.75, 100);
    
    self.fourButton.frame = CGRectMake(WIDTH / 18.75, 140, WIDTH / 3.75, 100);
    
    self.fiveButton.frame = CGRectMake(WIDTH / 2.67, 140, WIDTH / 3.75, 100);
    
    self.sixButton.frame = CGRectMake(WIDTH / 1.45, 140, WIDTH / 3.75, 100);
    
    
    //设置label尺寸
    self.oneLabel.frame = CGRectMake(WIDTH / 4.65 , 30, 20, 80);
    self.oneLabel.numberOfLines =0;
    self.oneLabel.font = [UIFont boldSystemFontOfSize:13];
    
    self.twoLabel.frame = CGRectMake(WIDTH / 1.85, 30, 20, 80);
    self.twoLabel.numberOfLines =0;
    self.twoLabel.font = [UIFont boldSystemFontOfSize:13];

    self.threeLabel.frame = CGRectMake(WIDTH / 1.15, 30, 20, 80);
    self.threeLabel.numberOfLines =0;
    self.threeLabel.font = [UIFont boldSystemFontOfSize:13];

    self.fourLabel.frame = CGRectMake(WIDTH / 4.65, 150, 20, 80);
    self.fourLabel.numberOfLines =0;
    self.fourLabel.font = [UIFont boldSystemFontOfSize:13];

    
    self.fiveLabel.frame = CGRectMake(WIDTH / 1.85, 150, 20, 80);
    self.fiveLabel.numberOfLines = 0;
    self.fiveLabel.font = [UIFont boldSystemFontOfSize:13];
    
    self.sixLabel.frame = CGRectMake(WIDTH / 1.15, 150, 20, 80);
    self.sixLabel.numberOfLines =0;
    self.sixLabel.font = [UIFont boldSystemFontOfSize:13];
  
}

- (void)createData
{
    self.labelArr = [NSMutableArray array];
    self.labelPicArr = [NSMutableArray array];
    self.labeltextArr = [NSMutableArray array];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"http://hunliji.com/v1/api/app/marks/recommend" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
       
        NSDictionary *dic = responseObject;
        NSArray *Arr = dic[@"marks"];
        for (NSDictionary *marksdic in Arr) {
            
            labelModel *label = [[labelModel alloc]init];
            [label setValuesForKeysWithDictionary:marksdic];
            
            [self.labelArr addObject:label];
            [self.labelPicArr addObject:label.image_path];
            
            [self.labeltextArr addObject:label.name];
            
            
            
            [label release];
            
        }
        
        [self.oneButton sd_setImageWithURL:[NSURL URLWithString:self.labelPicArr[0]] forState:UIControlStateNormal];
        [self.twoButton sd_setImageWithURL:[NSURL URLWithString:self.labelPicArr[1]] forState:UIControlStateNormal];
        [self.threeButton sd_setImageWithURL:[NSURL URLWithString:self.labelPicArr[2]] forState:UIControlStateNormal];
        [self.fourButton sd_setImageWithURL:[NSURL URLWithString:self.labelPicArr[3]] forState:UIControlStateNormal];
        [self.fiveButton sd_setImageWithURL:[NSURL URLWithString:self.labelPicArr[4]] forState:UIControlStateNormal];
        [self.sixButton sd_setImageWithURL:[NSURL URLWithString:self.labelPicArr[5]] forState:UIControlStateNormal];
        
        self.oneLabel.text =self.labeltextArr[0];
        self.twoLabel.text =self.labeltextArr[1];
        self.threeLabel.text =self.labeltextArr[2];
        self.fourLabel.text =self.labeltextArr[3];
        self.fiveLabel.text =self.labeltextArr[4];
        self.sixLabel.text =self.labeltextArr[5];
        
        

        [self.contentView reloadInputViews];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        
    }];
    
}







- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
